<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2023-09-14 12:31:39
 * @LastEditors: 卡卡 1071780426@qq.com
 * @LastEditTime: 2023-10-18 15:21:19
 * @FilePath: \mould\src\components\BehaViorManage\workYear\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="Control-1 mechanism_dialogS closure" id="comcn">
    <el-dialog
      :title="title"
      v-dialogDrag
      :visible.sync="visible"
      @close="closeDialog"
      :append-to-body="true"
      top="5%"
    >
      <div
        class="dialogBody common commonClassDialog"
        :style="{ height: dialogHeight }"
        style="width: 100%"
      >
        <tableData
          height="100%"
          :config="table_config"
          :dataList="tableData"
          :loading="loading"
          @click-change="rowChange"
        />
      </div>
      <div style="height: 50px"></div>
      <div class="newlyAdded_btn" v-if="btnShow">
        <el-button
          :disabled="isLock"
          type="primary"
          :disable="isLock"
          @click="yj_saveForm('formData')"
          >保存</el-button
        >
        <el-button type="warning" @click="visible = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TableData from "@/components/HntManage/el-tables"; //主页面列表
import {
  getCreditEvaluationFormByFid,
  markCreditEvaluationFormBySupervision, // 监理打分
  markCreditEvaluationFormByOwner,
} from "@/api/request.js";
export default {
  props: [
    "dialogVisible",
    "dialogTitle",
    "projectId",
    "status",
    "statusNum",
    "dataFid",
    "currentRow",
    "projectName",
    "stationType",
    "modelType",
  ],
  data() {
    return {
      visible: "",
      btnShow: false,
      title: "监理企业年度信用评价",
      isLock: false, // 控制按钮的disable属性
      btnStatus: [],
      dialogHeight: null,
      tableData: [],
      table_config: {
        imgKeyWord: "url",
        fileKeyWord: "url",
        fileName: "fFileName",
        dialogHeight: "",
        thead: [
          {
            label: "评价内容",
            prop: "fEvaluationcontent",
            minWidth: "80px",
            align: "center",
          },
          {
            label: "评价项目",
            prop: "fEvaluationproject",
            minWidth: "80px",
            align: "center",
          },
          {
            label: "失信行为代码",
            prop: "fBehaviorcode",
            minWidth: "80px",
            align: "center",
          },

          {
            label: "失信行为",
            prop: "fDishonestbehaviordesc",
            minWidth: "85px",
            align: "center",
          },
          {
            label: "信用等级或扣分标准",
            prop: "fCreditlevel",
            minWidth: "85px",
            align: "center",
          },
          {
            label: "监理自评(扣分)",
            prop: "fJldeduction",
            minWidth: "85px",
            align: "center",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
          },
          {
            label: "监理扣分依据及情况说明",
            prop: "fJldeductiondesc",
            minWidth: "85px",
            align: "center",
            type: "text",
            disabled: false, //是否禁用
            edit: true,
          },
          {
            label: "业主评分(扣分)",
            prop: "fProprietordeduction",
            minWidth: "85px",
            align: "center",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
          },
          {
            label: "业主扣分依据及情况说明",
            prop: "fProprietordeductiondesc",
            minWidth: "85px",
            align: "center",
            type: "text",
            disabled: false, //是否禁用
            edit: true,
          },
          {
            label: "备注",
            prop: "fNote",
            minWidth: "85px",
            align: "center",
          },
        ],
        isCheckBox: false,
        isIndex: true,
        isOperation: true,
        // 表格操作列
        operation: {
          label: "操作",
          width: "70",
          detail: true,
          prop: true,
          cols: [],
        },
      },
      loading: false,
    };
  },
  components: {
    TableData,
  },
  watch: {
    dialogVisible: {
      handler(newVal) {
        if (newVal) {
          console.log(888, newVal);
          this.visible = newVal;
        }
      },
      immediate: true,
    },
    dialogTitle: {
      handler(newVal) {
        if (newVal) {
          this.title = newVal;
        }
      },
      immediate: true,
    },

    projectId: {
      handler(newVal) {
        if (newVal) {
          console.log(787, newVal);
          this.getPerson(newVal);
        }
      },
      immediate: true,
    },
    status: {
      handler(newVal) {
        if (newVal) {
          this.btnStatus = newVal;
        }
      },
      immediate: true,
    },
    statusNum: {
      handler(newVal) {
        if (newVal) {
          this.edit(newVal);
        }
      },
      immediate: true,
    },
    dataFid: {
      handler(newVal) {
        if (newVal) {
          this.currntData = newVal;
          this.yj_searchForm(newVal);
        }
      },
      immediate: true,
    },
    currentRow: {
      handler(newVal) {
        if (newVal) {
          this.currentStatus = newVal;
        }
      },
      immediate: true,
    },
    modelType: {
      handler(newVal) {
        if (newVal) {
          console.log(newVal);
          if (newVal == 0) {
            this.btnShow = true;
          } else {
            this.btnShow = false;
          }
        }
      },
      immediate: true,
    },
  },
  created() {
    window.addEventListener("resize", this.getHeight);
    this.getHeight();
  }, //获取页面高度自适应：

  destroyed() {
    window.removeEventListener("resize", this.getHeight);
    this.getHeight();
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    this.getHeight();
  },
  methods: {
    yj_searchForm(data) {
      this.loading = true;
      var that = this;
      var obj = {
        fId: data,
      };
      that.tableData = [];
      getCreditEvaluationFormByFid(obj)
        .then((res) => {
          if (res.errcode == 0) {
            that.loading = false;
            if (this.userInfo.companyNature == "总监办") {
              that.tableData = res.data.formList;
              if (this.btnShow == true) {
                this.table_config.thead[6].edit = true;
                this.table_config.thead[5].edit = true;
                this.table_config.thead[7].edit = false;
                this.table_config.thead[8].edit = false;
              } else {
                this.table_config.thead[5].edit = false;
                this.table_config.thead[6].edit = false;
                this.table_config.thead[7].edit = false;
                this.table_config.thead[8].edit = false;
              }
            } else {
              that.tableData = res.data.formList;
              if (this.btnShow == true) {
                this.table_config.thead[6].edit = false;
                this.table_config.thead[5].edit = false;
                this.table_config.thead[7].edit = true;
                this.table_config.thead[8].edit = true;
              } else {
                this.table_config.thead[5].edit = false;
                this.table_config.thead[6].edit = false;
                this.table_config.thead[7].edit = false;
                this.table_config.thead[8].edit = false;
              }
            }
          } else {
            this.$message.error("列表数据获取失败", res.msg);
            this.loading = false;
          }
        })
        .catch((error) => {
          this.$message.error("列表数据 接口出错", error.msg);
          this.loading = false;
        });
    },
    rowChange(row) {
      console.log(row);
    },
    getHeight() {
      var h = document.documentElement.clientHeight; //获取页面可见高度
      this.dialogHeight = h * 0.76 + "px";
    },
    handleSelect(key) {
      this.activeIndex = key;
    },
    closeDialog() {
      this.$emit("close");
    },
    // 保存
    yj_saveForm() {
      // 设置按钮不可点击（disable: false）
      this.isLock = true;
      if (this.userInfo.companyNature == "总监办") {
        var data = {
          userId: this.userInfo.userId, //当前登陆用户id
          userName: this.userInfo.realName, //当前登陆用户名称
          fId: this.dataFid,
          creditEvalutionformList: this.tableData,
        };

        markCreditEvaluationFormBySupervision(data)
          .then((res) => {
            if (res.errcode == 0) {
              this.isLock = false;
              // this.yj_searchForm(this.getList);
              this.visible = false;
              this.$emit("refreshList");
              this.$message.success("新增成功");
            } else {
              this.isLock = false;
              this.$message.error(res.msg);
              console.log("接口报错");
            }
          })
          .catch((error) => {
            console.log("拌合站设置-新增）", error);
          });
      } else {
        var data1 = {
          userId: this.userInfo.userId, //当前登陆用户id
          userName: this.userInfo.realName, //当前登陆用户名称
          fId: this.dataFid,
          creditEvalutionformList: this.tableData,
        };

        markCreditEvaluationFormByOwner(data1)
          .then((res) => {
            if (res.errcode == 0) {
              this.isLock = false;
              // this.yj_searchForm(this.getList);
              this.visible = false;
              this.$emit("refreshList");
              this.$message.success("新增成功");
            } else {
              this.isLock = false;
              this.$message.error(res.msg);
              console.log("接口报错");
            }
          })
          .catch((error) => {
            console.log("拌合站设置-新增）", error);
          });
      }
    },
  },
};
</script>
<style lang="less" scoped>
.comcn /deep/.el-dialog {
  width: 60% !important;
}
</style>
